const jwt = require("jsonwebtoken")

module.exports = () => {
    return async function auth(ctx, next) {
        const {authorization}=ctx.request.header;
        if(authorization){
            const token = authorization.split('')[1]
            try{
                jwt.verify(token,app.config.keys)
            }catch(err){
                ctx.status=401,
                ctx.body="鉴权失败"
            }
        }else{
            ctx.status=401,
            ctx.body="无权限"
        }
      await next();
    };
  };